package com.woke.adapter;

import java.util.ArrayList;
import java.util.List;

import com.zhongcai.online.R;
import com.woke.data.Data_child;

import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Mylistadter extends BaseAdapter{
	private LayoutInflater mInflater;
	private List<Data_child> datalist;
	private int phonewid;

	public Mylistadter(LayoutInflater minflater, ArrayList<Data_child> datalist, int phonewid) {
		this.mInflater = minflater;
		this.datalist = datalist;
		this.phonewid = phonewid;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datalist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	class Holder {
		TextView mTpeople;
		TextView mTname;
		TextView mTmoney;
		TextView mTok;
		TextView mTdescrise;
		ImageView mIcon;
		
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView == null){
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.item_adter_child, null);
			holder.mIcon = (ImageView)convertView.findViewById(R.id.item_adter_chilidmap);
			holder.mTmoney = (TextView)convertView.findViewById(R.id.item_adter_chilidmoney);
			holder.mTname = (TextView)convertView.findViewById(R.id.item_adter_chilidname);
			convertView.setTag(holder);
		}else{
			 holder = (Holder) convertView.getTag();
		}
		Data_child data = datalist.get(position);
		BitmapFactory.Options op = new BitmapFactory.Options();
//		LayoutParams params = holder.mIcon.getLayoutParams();
//		params.height = phonewid / 3 - 8;
//		params.width = phonewid / 3 - 8;
//		holder.mIcon.setLayoutParams(params);
		op.inSampleSize = 2;
		holder.mTmoney.setText("支持 "+data.money+"元");
		holder.mTname.setText(data.name);
		if(null != BitmapFactory.decodeFile(data.img,op)){
		holder.mIcon.setImageBitmap(BitmapFactory.decodeFile(data.img,op));
		}
		return convertView;
	}
}
